#ifndef __CORE_FILESYS_FILES_H__
#define __CORE_FILESYS_FILES_H__

/**
 *  core/filesys/files.h
 *  funkce pro praci se soubory
 *  v souborovem systemu FAT12
 */

#define FNEW_OK              (1)
#define FNEW_FAILED          (0)

#define FSEEK_OK             (1)
#define FSEEK_BREAK          (0)

#define REMOVE_OK            (1)
#define REMOVE_FAILED        (0)

#define RENAME_OK            (1)
#define RENAME_FAILED        (0)

#define SEEK_SET             (0)
#define SEEK_CUR             (1)
#define SEEK_END             (2)

/* struktura FILE */
typedef struct {
  char          filename[12]; /* jmeno souboru    */
  char far *    buffer;       /* buffer           */
  unsigned int  c_start;      /* zacatek souboru  */
  unsigned int  c_actual;     /* aktualni cluster */
  unsigned int  pos;          /* pozice v clustru */
  unsigned int  abs_pos;      /* absolutni pozice */
  unsigned int  size;         /* velikost souboru */

  unsigned int  dir_cluster;  /* cluster slozky, odkud je soubor */
  unsigned int  dir_pos;      /* pozice souboru ve slozce */
  DirectoryEntry *sfile;      /* jednotka souboru */
} FILE;

int           file_new            (char far *filename);
FILE far *    file_open_care      (char far *filename, bool dirs_too);
FILE far *    file_open           (char far *filename, char far *mode);
FILE far *    file_dir_open       (char far *filename);
int           file_seek           (FILE far *stream, int seek, int whence);
int           file_tell           (FILE far *stream);
bool          end_of_file         (FILE far *stream);
int           file_size           (FILE far *stream);
void far *    file_read           (char far *buffer, int size, FILE far *stream);
void          file_write          (char far *buffer, int size, FILE far *stream);
void          file_close          (FILE far *stream);
int           file_remove         (char far *filename);
int           file_rename         (const char far *oldnamec, const char far *newname);

#include <core/init.h>
#include <core/filesys/entries.h>
#include <core/filesys/dirs.h>
#include <source/core/filesys/files.c>

#endif
